'use strict';

let
    Koa = require('koa'),
    port = 7666,
    app = new Koa(),
    router = require('koa-router')(),
    njkMiddleWare = require('./tempMiddleWare')


// app.use(async (ctx, next) => {
//     ctx.render = (view, model) => {
//         ctx.body = nunjucks.render(view, model)
//     }
//     await next();
// })

router.get('/', async ctx => {
    await ctx.render('./forin.html', {
        username: 'GiGi',
        num: 5,
        userArr: [
            { id: 1, name: 'GiGi', age: 20 },
            { id: 2, name: 'Curry', age: 32 },
            { id: 3, name: 'Bluss', age: 40 },
            { id: 4, name: 'David', age: 52 },
        ],
        str: 'hello world'
    })
})

app.use(njkMiddleWare);

app.use(router.routes());

app.listen(port);

console.log(`http://localhost:${port}`);